package com.flash.InventoryManagement.service.impl;

import com.flash.InventoryManagement.entity.CashStock;
import com.flash.InventoryManagement.entity.TaStock;
import com.flash.InventoryManagement.mapper.TaStockMapper;
import com.flash.InventoryManagement.service.TaStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author jr
 * @version 1.0
 * @date 2022/9/1
 */
@Service
public class TaStockServiceImpl implements TaStockService {

    @Autowired
    TaStockMapper taStockMapper;

    @Override
    public int countTaStock() {
        return taStockMapper.countTaStock();
    }

    @Override
    public List<TaStock> selectTaStock(TaStock taStock, int page, int limit) {
        HashMap map = new HashMap();
        map.put("strWhere", buildWhere(taStock));
        map.put("page",(page-1)*limit+1);
        map.put("limit",limit*page);
        return taStockMapper.selectTaStock(map);
    }

    @Override
    public int insertTaStock(TaStock taStock) {
        return taStockMapper.insertTaStock(taStock);
    }

    @Override
    public int deleteTaStock(TaStock taStock) {
        return taStockMapper.deleteTaStock(taStock);
    }

    @Override
    public int updateTaStock(TaStock taStock) {
        return taStockMapper.updateTaStock(taStock);
    }

    public String buildWhere (TaStock taStock) {
        StringBuffer strWhere = new StringBuffer();
        if (taStock.getSecurityAccrualStockId()!=null && !taStock.getSecurityAccrualStockId().equals("")){
            strWhere.append(" and securityAccrualStockId like '%" + taStock.getSecurityAccrualStockId() +"%'" );
        }
        if (taStock.getDateTAStock()!=null && !taStock.getDateTAStock().equals("")){
            strWhere.append(" and dateTAStock like '%" + taStock.getDateTAStock() +"%'" );
        }
        return strWhere.toString();
    }
}
